<?php

namespace App\Helpers;

use App\Exception\ApiException;
use JiGuang\JSMS;

class SmsJiguangUtil
{
    //public $appKey = 'f2ffeae311dcdfcd37f0b2be';
    //public $masterSecret = 'a89b390aaf92846d954fe422';
    //public $captchaTempId = '225941';
    public $appKey = 'c7a087bc62eb6b3da97dcb3b';
    public $masterSecret = '6518537cf92c1db03723049b';
    public $captchaTempId = '238827';
//    public $accountId = '';
//    public $password = '';

    public function __construct()
    {
    }

    public function sendCaptcha($phone,$appName,$captcha)
    {
        $client = new JSMS($this->appKey, $this->masterSecret);

        $temp_para =[
            'name' => $appName,
            'captcha' => $captcha
        ];
        $response = $client->sendMessage($phone, $this->captchaTempId, $temp_para);

//        $response = json_decode($response,true);

        if (isset($response['error'])) {
            throw new ApiException($response['error']['message']);
        }

        return $response;
    }
}
